package com.wuster.controller;

import com.wuster.result.Result;
import com.wuster.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * ClassName: FileUploadController
 * Package: com.wuster.controller
 * Description: TODO
 *
 * @Author VictoriaZhou
 * @Create 2024/7/4 13:14
 * @Version 1.0
 */
@Slf4j
@Api(tags="文件管理")
@RequestMapping("/file")
@RestController
public class FileUploadController {
    @Autowired
    private FileService service;

    @ApiOperation("上传文件")
    @PostMapping("upload")
//    public Result<String> upload(@RequestPart(value= "file") @RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
    public Result<String> upload(@RequestPart(value= "file") @RequestParam(value = "file")  MultipartFile file) throws IOException {
        String imageUrl = service.upload(file);
        log.info(imageUrl);
        return Result.success(imageUrl);
    }

}

